layui.config({
	base : "js/"
}).use(['form','layer','jquery','layedit'],function(){
	var form = layui.form(),
		layer = parent.layer === undefined ? layui.layer : parent.layer,
		laypage = layui.laypage,
		layedit = layui.layedit,
		$ = layui.jquery;

	//创建一个编辑器
	
 	var editIndex = layedit.build('news_content');
 	var addNewsArray = [],addNews;

     $.get($.httpRootPath()+"/api/sys/notice",function(data){
    	console.log("department");
    	data =  JSON.parse(data);
    	if(data.code == "00"){
    		$(".subContent").val(data.data);
    	}
    	console.log(data.data);
    })
 	form.on("submit(subInfo)",function(data){
 		layedit.sync(editIndex);
 		//弹出loading
 		var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
   		var data = {
       		news_content: $("#news_content").val(),
       		content:$(".subContent").val()
   		 };
 		updateInfo(data,function(){
 			top.layer.close(index);
 			layer.closeAll("iframe");
	 		//刷新父页面
//	 		parent.location.reload();
 		})
 		return false;
 	})
})
function updateInfo(data, callback) {
	$.ajax({
		url: $.httpRootPath() + '/api/sys/notice',
		type: 'POST',
		dataType: 'json',
		data: data,
		timeout: 15000,
		cache: false,
		success: function(r) {
			if(r.code == "00") {
				layer.msg("更新成功！");
			} else {
				layer.msg("更新失败！");
			}
		},
		error: function(e) {
			layer.msg("系统错误！");
		},
		complete: function() {
			callback();
		}
	});
	}
